import java.awt.AWTException;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFrame;

import javax.swing.JOptionPane;

class SystemTrayDemo {
    public SystemTrayDemo(){
        JFrame frame = new  JFrame();
        
        try {
            if (!SystemTray.isSupported()) {
                System.out.println("SystemTray is not supported");
                return;
            }            
            SystemTray tray = SystemTray.getSystemTray();
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            Image image = toolkit.getImage(getClass().getResource("Images/icon.png"));
            
            PopupMenu menu = new PopupMenu();
            
            MenuItem messageItem = new MenuItem("Show Message");
            messageItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JOptionPane.showMessageDialog(null, "www.java2s.com");
                }
            });
            menu.add(messageItem);
            
            MenuItem closeItem = new MenuItem("Close");
            closeItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.exit(0);
                }
            });
            menu.add(closeItem);
            TrayIcon icon = new TrayIcon(image, "SystemTray Demo", menu);
            icon.setImageAutoSize(true);            
            tray.add(icon);
        } catch (AWTException ex) {
            Logger.getLogger(SystemTrayDemo.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

  public static void main(String[] args)throws Exception {
    new SystemTrayDemo();
  }
}